<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

namespace app\admin\model;

use think\Model;

/**
 * Description of Task
 *
 * @author Administrator
 */
class Task extends Model {

    protected $name = 'task';
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';
    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    // 追加属性
    protected $append = [
        'expenditure',
        'income',
        'zincome'
        
    ];

    public function getSubtimeTextAttr($value, $data) {
        $value = $value ? $value : $data['subtime'];
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    public function getEndtimeTextAttr($value, $data) {
        $value = $value ? $value : $data['endtime'];
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function getSubtime1Attr($value, $data) {
        return intval($data['subtime'] / 3600);
    }

    protected function getSubtime2Attr($value, $data) {
        return ($data['subtime'] % 3600) / 60;
    }

    public function getExpenditureAttr($value, $data) {
        return $data['commission'] * $data['number'];
    }

    public function getIncomeAttr($value, $data) {
        return $data['price'] * $data['number'];
    }

    public function getZincomeAttr($value, $data) {
        return $data['price'] * $data['number']-$data['commission'] * $data['number']- $data['onefee']-$data['twofee'];
    }



}
